#!/usr/bin/env bash

CPATH=$(cd `dirname $0`;pwd)
TOOLS="$CPATH/../lib"
source $TOOLS/lib.sh

if [[ $# -lt 4 ]];then
    echo "please specify package name usage: ./sync_all_obs_pkg.sh <obs_source_ip> <username> <password> <manifest-file> <exitonfailure>"
    exit 1
fi

OBS_SOURCE_IP=$1
USERNAME=$2
PASSWORD=$3
MANIFESTFILE=$4
EXITONFAILURE=$5
REVERSE_DELETE=$6

CACHE_DIR="/srv/cache/obs/tar_scm/repo/next/openEuler"

sh ${TOOLS}/sshscp.sh -p "${PASSWORD}" -s "refresh.sh" -d "${OBS_SOURCE_IP}:~"
sh ${TOOLS}/sshscp.sh -p "${PASSWORD}" -s ${MANIFESTFILE} -d "${OBS_SOURCE_IP}:~"
sh ${TOOLS}/sshcmd.sh -c "./refresh.sh ~/${MANIFESTFILE} ${EXITONFAILURE} ${REVERSE_DELETE}" -m "${OBS_SOURCE_IP}" -u ${USERNAME} -p ${PASSWORD}
